Imports System.Drawing.Drawing2D

Public Class UcnPenPopupControl
    'represents PopupContainerControl for setting a MindFusion.Drawing.Pen

#Region "Attributes"
#Region "Private attributes"
    Private MbReadyForUse As Boolean = False 'indicates proper creation or first initialization of usercontrol
#End Region
#End Region
#Region "Constructors & Init"
    Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.


        '**********************************************************************
        InitControl()
        '**********************************************************************
    End Sub
    Sub New(ByVal IoPen As MindFusion.Drawing.Pen)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.


        '**********************************************************************
        InitControl()
        Init(IoPen)
        '**********************************************************************
    End Sub
    'setting usercontrol settings before its using
    Private Function InitControl() As GeActionResult
        SetReadyForUse(False) 'disabling usercontrol
        Try
            Me.Dock = DockStyle.Fill
            Init(MFPenVirginCreator(Color.Black, 1))

            SetReadyForUse(True) 'enabling usercontrol
            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'initialization of controls
    Public Function Init(ByVal IoPen As MindFusion.Drawing.Pen) As GeActionResult
        Try
            If MbReadyForUse Then
                If IoPen IsNot Nothing Then
                    ceColor.Color = IoPen.Color
                    edtWidth.Value = IoPen.Width
                Else
                    ceColor.Color = Color.Black
                    edtWidth.Value = 1
                End If

                Return GeActionResult.kkOk
            Else
                LogEvent("Neinicializovany UcnPenPopupControl!", , )
                Return GeActionResult.kkError
            End If
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
#End Region
#Region "Properties"
#Region "Public properties"
    Public ReadOnly Property ReadyForUse() As Boolean
        Get
            Return MbReadyForUse
        End Get
    End Property
    'Pen - result of this "control"
    Public ReadOnly Property Result() As MindFusion.Drawing.Pen
        Get
            Return New MindFusion.Drawing.Pen(ceColor.Color, edtWidth.Value)
        End Get
    End Property
#End Region
#End Region
#Region "Events handler"
    'repainting of preview 
    Private Sub PopupContainerControl_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PopupContainerControl.Paint
        PaintPreview()
    End Sub
    'repainting of preview 
    Private Sub edtWidth_EditValueChanging(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles edtWidth.EditValueChanging
        PaintPreview()
    End Sub
    'repainting of preview 
    Private Sub edtWidth_EditValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles edtWidth.EditValueChanged
        PaintPreview()
    End Sub
#End Region
#Region "Subs"
    'sets MbReadyForUse attribute and sets Enable property of usercontrol
    Private Sub SetReadyForUse(ByVal IbValue As Boolean)
        MbReadyForUse = IbValue
        Me.Enabled = IbValue 'enabling usercontrol
    End Sub
    'painting of preview
    Private Sub PaintPreview()
        Dim LoHwnd As IntPtr = PopupContainerControl.Handle
        Dim LoGraphics As System.Drawing.Graphics = Graphics.FromHwnd(LoHwnd)

        Dim LoRectangleF As RectangleF = SDRectangleFVirginCreator(200, 20, 90, 100)
        Dim LoColor As Color = ceColor.Color
        Dim LnWidth As Single = edtWidth.Value
        Dim LiX, LiY As Integer
        LiX = 110
        LiY = 75
        'clearing a area
        LoGraphics.DrawLine(SDPenVirginCreator(PopupContainerControl.BackColor, 20), LiX, LiY, LiX + 80, LiY)
        LoGraphics.DrawLine(SDPenVirginCreator(LoColor, LnWidth), LiX, LiY, LiX + 80, LiY)
    End Sub
#End Region

End Class
